<%--
  Created by IntelliJ IDEA.
  User: suyuwei
  Date: 2018/5/23
  Time: 9:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>线路管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/dgfp_39_hz/statics/bootstrap/css/bootstrap.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/dgfp_39_hz/statics/table/bootstrap-table.min.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/statics/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/assets/js/laydate/laydate.js"></script>
    <script src="${pageContext.request.contextPath}/dgfp_39_hz/assets/js/jquery-3.1.1.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/statics/ajaxfileupload.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/statics/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/statics/table/bootstrap-table.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/dgfp_39_hz/statics/table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${pageContext.request.contextPath}/dgfp_39_hz/statics/bootstrap/js/tableExport.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/sweetalert.css">
    <script src="${pageContext.request.contextPath}/css/sweetalert.min.js"></script>
   <%-- return "<a href='javascript:upd(\"+row.id+\")'>停用</a>&nbsp;|&nbsp;--%>
    <script type="text/javascript">
        $(function(){
            $('#table').bootstrapTable({
                url: '${pageContext.request.contextPath}/roleline/queryConditionPage',
                columns: [
                    {
                        checkbox:true
                    },
                    {
                        field: 'xlid',
                        title: '路线编号'
                    }, {
                        field: 'xlname',
                        title: '路线名称'
                    },
                    {
                        field: 'qsganhao',
                        title: '起始杆号'
                    },  {
                        field: 'zzganhao',
                        title: '终止杆号'
                    },  {
                        field: 'tajishu',
                        title: '塔基数'
                    },{
                        field: 'runningstate',
                        title: '运行状态',
                        formatter:function(value,row,index) {
                            if (value == 1) {
                                return "正常";
                            }
                            return "检修中";
                        }
                    },{
                        field: 'startstate',
                        title: '是否启用',
                        formatter:function(value,row,index) {
                            if (value == 1) {
                                return "启用";
                            }
                            return "不启用";
                        }
                    },
                    {
                        field : 'xx',
                        title : '操作',
                        formatter:function(value,row,index){
                            return "<a href='javascript:upd("+row.id+")'>修改</a>&nbsp;|&nbsp;<a href='javascript:del("+row.id+")'>删除</a>" ;
                        }
                    }],

                clickToSelect:true,
                singleSelect:true,
                striped : true,
                toolbar:"#toolbar",
                method:'post',
                contentType:"application/x-www-form-urlencoded",
                queryParamsType:'',
                queryParams:queryParams,
                height:360,
                pageList:[5,10,15],
                pageNumber:1,
                pageSize:5,
                pagination:true,
                sidePagination:'server'

            });
        }) ;
      var id  ;

        function del(sid){
            $("#cc").modal('show');
            var opt = $("#table").bootstrapTable('getOptions') ;
            var xlid = $("#xlid").val() ;
            var runningstate = $("#runningstate").val() ;
            id = sid ;
            $("#cc").modal('hide');
            $.post("${pageContext.request.contextPath}/roleline/deleteRole",{"id":id,'xlid':xlid,'runningstate':runningstate,'pageSize':opt.pageSize,'pageNumber':opt.pageNumber},function(data){
                $("#table").bootstrapTable('load',data);
            })

     }
     function upd(sid) {
         $("#myModal2").modal("show") ;
         $.post("${pageContext.request.contextPath}/roleline/oneRole",{"id":sid},function(data){
             console.log(data)
             console.log(data.qsganhao);
             $("#xgxlid").val(data.xlid);
             $("#xgqsganhao").val(data.qsganhao);
             $("#xgremark").val(data.remark);
             $("#xgtajishu").val(data.tajishu);
             $("#xgxlname").val(data.xlname);
             $("#xgcreationDate").val(data.creationDate);
             $("#xgzzganhao").val(data.zzganhao);
             /*
             $('input:radio:checked').val(data.startstate);*/
         })
     }
        function update() {
            var xgcreationDate = $("#xgcreationDate").val();
            var xgxlid = $("#xgxlid").val() ;
            var xgxlname = $("#xgxlname").val() ;
            var xgtajishu = $("#xgtajishu").val() ;
            var xgqsganhao = $("#xgqsganhao").val() ;
            var xgzzganhao = $("#xgzzganhao").val();
            var xgremark = document.getElementById("xgremark").value;
            var startstate=$('input:radio:checked').val();
            var opt = $("#table").bootstrapTable('getOptions') ;
            var xlid = $("#xlid").val() ;
            var runningstate = $("#runningstate").val() ;
            $("#myModal2").modal("hide") ;
            $.post("${pageContext.request.contextPath}/roleline/updateRole",{"xgxlid":xgxlid,"xgxlname":xgxlname,"xgqsganhao":xgqsganhao,"xgzzganhao":xgzzganhao,"xgtajishu":xgtajishu,"startstate":startstate,"xgcreationDate":xgcreationDate,"xgremark":xgremark,'xlid':xlid,'runningstate':runningstate,'pageSize':opt.pageSize,'pageNumber':opt.pageNumber},function(data){
                alert("修改成功");
                $("#table").bootstrapTable("load",data) ;
            }) ;
        }
        function search(){
            var opt = $("#table").bootstrapTable('getOptions') ;
            var xlid = $("#xlid").val() ;
            var runningstate = $("#runningstate").val() ;
            $.post('${pageContext.request.contextPath}/roleline/queryConditionPage',{'xlid':xlid,'runningstate':runningstate,'pageSize':opt.pageSize,'pageNumber':opt.pageNumber},function(data){
                //重新给table绑定数据
                $("#table").bootstrapTable("load",data) ;
            }) ;
        }

        function queryParams (params) {
            var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                'pageSize': params.pageSize,  //页面大小
                'pageNumber': params.pageNumber, //页码
                'xlid':$("#xlid").val(),
                'runningstate':$("#runningstate").val()
            };
            return temp;
        };

        laydate.render({

            elem:'#time'

        })
        function save(){
            //接收数据
            var xzxlid = $("#xzxlid").val() ;
            var xzxlname = $("#xzxlname").val() ;
            var tajishu = $("#tajishu").val() ;
            var qsganhao = $("#qsganhao").val() ;
            var zzganhao = $("#zzganhao").val();
            var remark = document.getElementById("remark").value;
            var startstate=$('input:radio:checked').val();
            var opt = $("#table").bootstrapTable('getOptions') ;
            var xlid = $("#xlid").val() ;
            var runningstate = $("#runningstate").val() ;

            $("#myModal").modal("hide") ;
            //
            $.post("${pageContext.request.contextPath}/roleline/saveRole",{"xzxlid":xzxlid,"xzxlname":xzxlname,"qsganhao":qsganhao,"zzganhao":zzganhao,"tajishu":tajishu,"startstate":startstate,"remark":remark,'xlid':xlid,'runningstate':runningstate,'pageSize':opt.pageSize,'pageNumber':opt.pageNumber},function(data){
                alert("添加成功");
                $("#table").bootstrapTable("load",data) ;
            }) ;
        }
        function del1(){
            var opt = $("#table").bootstrapTable('getOptions') ;
            var xlid = $("#xlid").val() ;
            var runningstate = $("#runningstate").val() ;
            //1.确定是否选中行
            var arr = $("#table").bootstrapTable('getSelections') ;
            if(arr.length==0){
                alert("请选中要删除的行") ;
            }
            else {
                //1.得到选中行的主键/id
                var id = arr[0].id;


                swal({
                        title: "确定删除吗？",
                        text: "你将无法恢复该虚拟文件！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定删除！",
                        cancelButtonText: "取消删除！",
                        closeOnConfirm: false,
                        closeOnCancel: false
                    },
                    function (isConfirm) {
                        if (isConfirm) {
                            $.post("${pageContext.request.contextPath}/roleline/deleteRole",{"id":id,'xlid':xlid,'runningstate':runningstate,'pageSize':opt.pageSize,'pageNumber':opt.pageNumber},function(data){
                                $("#table").bootstrapTable('load',data);
                                swal("删除！", "你的虚拟文件已经被删除。",
                                    "success");
                            })
                        } else {
                            swal("取消！", "你的虚拟文件是安全的:)",
                                "error");
                        }
                    });
            }}
    </script>
</head>
<body>
<!--搜索面板-->
<div class="panel panel-default">
    <div class="panel-body">
        <form class="form-inline">
            <div class="form-group">
               路线编码：<input id="xlid" type="text" class="form-control" placeholder="搜索内容">
            </div>

            路线状态:
            <select id="runningstate" class="form-control">
                <option value="-1">--请选择--</option>
                <option value="1">正常</option>
                <option value="2">检修中</option>
            </select>

         <button onclick="search()" type="button" class="btn btn-default">查询</button>
            <button type="button" id="download" style="margin-left:50px" id="btn_download" class="btn btn-primary" onClick ="$('#table').tableExport({ type: 'excel', escape: 'false' })">数据导出</button>
        </form>

    </div>
</div>
<div id="btndiv">
    <button type="button" class="btn" data-toggle="modal"
            data-target="#myModal">增加</button>
    <button type="button" class="btn" data-toggle="modal"
            data-target="#myModal">修改</button>
    <button type="button" class="btn" onclick="del1()">
        <span class="glyphicon glyphicon-trash"></span>删除
    </button>
</div>

<!-- 模态框 -->
<table id="table" data-classes="table table-hover"></table>
<!-- Modal -->
<div class="modal fade" id="myModal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">增加线路</h4>
            </div>
            <div class="modal-body">
                <!-- form开始 -->
                <form  method="post">
                    <div class="form-group">
                        <label for="xzxlid" class="col-sm-4 control-label">线路编码 *</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="xzxlid" parsley-trigger="change" parsley-required="true" parsley-minlength="4" parsley-validation-minlength="1">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="xzxlname" class="col-sm-4 control-label">线路名称 *</label>
                        <div class="col-sm-8">
                            <input type="email" class="form-control" id="xzxlname" parsley-trigger="change" parsley-required="true" parsley-minlength="4" parsley-type="email" parsley-validation-minlength="1">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="time" class="col-sm-4 control-label">投运日期</label>
                        <div class="col-sm-8">
                            <input type="date" name="date" id="time"  class="form-control"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="tajishu" class="col-sm-4 control-label">塔基数 *</label>
                        <div class="col-sm-8">
                            <%--  <textarea class="form-control" id="input05" rows="3" parsley-trigger="keyup" parsley-rangelength="[20,200]" parsley-validation-minlength="1"></textarea>
                        --%>
                            <input type="text" class="form-control" id="tajishu" parsley-trigger="change" parsley-minlength="4" parsley-type="dateIso" parsley-validation-minlength="1">

                        </div>
                    </div>


                    <div class="form-group">
                        <label for="qsganhao" class="col-sm-4 control-label">起始编号 *</label>
                        <div class="col-sm-8" id="selectbox">
                          <%--  <select class="chosen-select chosen-transparent form-control" id="input07" parsley-trigger="change" parsley-required="true" parsley-error-container="#selectbox">
                                <option value="">Please choose</option>
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                            </select>--%>
                              <input type="text" class="form-control" id="qsganhao" parsley-trigger="change" parsley-minlength="4" parsley-type="dateIso" parsley-validation-minlength="1">

                        </div>
                    </div>

                    <div class="form-group">
                        <label for="zzganhao" class="col-sm-4 control-label">终止杆号 *</label>
                        <div class="col-sm-8" id="selectbox2">
                           <%-- <select class="chosen-select chosen-transparent form-control" id="input08" parsley-trigger="change" parsley-required="true" parsley-error-container="#selectbox">
                                <option value="">Please choose</option>
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                            </select>--%>
                               <input type="text" class="form-control" id="zzganhao" parsley-trigger="change" parsley-minlength="4" parsley-type="dateIso" parsley-validation-minlength="1">

                        </div>
                    </div>
                    <div class="form-group">
                        <label for="remark" class="col-sm-4 control-label">备注 *</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" name="remark" id="remark" rows="3" parsley-trigger="keyup" parsley-rangelength="[20,200]" parsley-validation-minlength="1"></textarea>

                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">是否停用</label>
                        <div class="col-sm-8">
                            <div class="radio radio-transparent">
                                <input type="radio" name="state" id="optionsRadios1" value="1">
                                <label for="optionsRadios1">正常</label>
                            </div>
                            <div class="radio radio-transparent">
                                <input type="radio" name="state" id="optionsRadios2" value="0">
                                <label for="optionsRadios2">停用</label>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
              <button onclick="save()" type="button" class="btn btn-primary">提交</button>
              <%--  <input type="submit" value="注册">--%>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal2">
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"
                    aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            <h4 class="modal-title" id="myModalLabe2">修改线路</h4>
        </div>
        <div class="modal-body">
            <!-- form开始 -->
            <form  method="post">
                <div class="form-group">
                    <label for="xzxlid" class="col-sm-4 control-label">线路编码 *</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" value="${xlid}" id="xgxlid" parsley-trigger="change" parsley-required="true" parsley-minlength="4" parsley-validation-minlength="1">
                    </div>
                </div>

                <div class="form-group">
                    <label for="xzxlname" class="col-sm-4 control-label">线路名称 *</label>
                    <div class="col-sm-8">
                        <input type="email" class="form-control" value="${xlname}" id="xgxlname" parsley-trigger="change" parsley-required="true" parsley-minlength="4" parsley-type="email" parsley-validation-minlength="1">
                    </div>
                </div>

                <div class="form-group">
                    <label for="xgcreationDate" class="col-sm-4 control-label">投运日期</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" value="${creationDate}" id="xgcreationDate" parsley-trigger="change" parsley-minlength="4" parsley-type="dateIso" parsley-validation-minlength="1" placeholder="YYYY-MM-DD">
                    </div>
                </div>

                <div class="form-group">
                    <label for="tajishu" class="col-sm-4 control-label">塔基数 *</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" value="${tajishu}" id="xgtajishu" parsley-trigger="change" parsley-minlength="4" parsley-type="dateIso" parsley-validation-minlength="1">

                    </div>
                </div>


                <div class="form-group">
                    <label for="qsganhao" class="col-sm-4 control-label">起始编号 *</label>
                    <div class="col-sm-8" id="selectbox1">
                        <input type="text" class="form-control" value="${qsganhao}" id="xgqsganhao" parsley-trigger="change" parsley-minlength="4" parsley-type="dateIso" parsley-validation-minlength="1">

                    </div>
                </div>

                <div class="form-group">
                    <label for="zzganhao" class="col-sm-4 control-label">终止杆号 *</label>
                    <div class="col-sm-8" id="selectbox3">

                        <input type="text" class="form-control" value="${zzganhao}" id="xgzzganhao" parsley-trigger="change" parsley-minlength="4" parsley-type="dateIso" parsley-validation-minlength="1">

                    </div>
                </div>
                <div class="form-group">
                    <label for="remark" class="col-sm-4 control-label">备注 *</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" name="remark" id="xgremark" rows="3" parsley-trigger="keyup" parsley-rangelength="[20,200]" parsley-validation-minlength="1">${remark}</textarea>

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-4 control-label">是否停用</label>
                    <div class="col-sm-8">
                        <div class="radio radio-transparent">
                            <input type="radio" name="xgstate" id="optionsRadios3" value="1">
                            <label for="optionsRadios1">正常</label>
                        </div>
                        <div class="radio radio-transparent">
                            <input type="radio" name="xgstate" id="optionsRadios4" value="0">
                            <label for="optionsRadios2">停用</label>
                        </div>
                        <input type="hidden" name="state2" value="${startstate}">
                    </div>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button onclick="update()" type="button" class="btn btn-primary">修改</button>
        </div>
    </div>
</div>
</div>
<div id="cc" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">提示标题</h4>
            </div>
            <div class="modal-body">
                <p>确定删除吗?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button onclick="cf()" type="button" class="btn btn-primary">确定</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
